import cache from '@/plugins/cache.js';

const TOKEN_KEY = 'admin-token';
const SESSION_GENERATE_ID = 'session_generate_id';
const USER_INFO = 'user_info';
const SYSTEM_SETTING = 'system_setting';
const LANGUAGE = "language";

export class CacheUtil {
  static getToken() {
    return cache.local.get(TOKEN_KEY);
  }

  static setToken(token) {
    cache.local.set(TOKEN_KEY, token);
  }

  static removeToken() {
    cache.local.remove(TOKEN_KEY);
  }

  static getSessionGenerateId() {
    return cache.local.get(SESSION_GENERATE_ID);
  }

  static setSessionGenerateId(sessionGenerateId) {
    cache.local.set(SESSION_GENERATE_ID, sessionGenerateId);
  }

  static removeSessionGenerateId() {
    cache.local.remove(SESSION_GENERATE_ID);
  }

  static getUserInfo() {
    return JSON.parse(cache.local.get(USER_INFO));
  }

  static setUserInfo(userInfo) {
    cache.local.set(USER_INFO, JSON.stringify(userInfo));
  }

  static removeUserInfo() {
    cache.local.remove(USER_INFO);
  }

  static clear() {
    cache.local.clearCache();
  }

  static getSystemSetting() {
    return JSON.parse(cache.session.get(SYSTEM_SETTING));
  }

  static setSystemSetting(key, value) {
    let setting = CacheUtil.getSystemSetting() ? CacheUtil.getSystemSetting() : {};
    setting[key] = value
    cache.session.set(SYSTEM_SETTING, JSON.stringify(setting));
  }

  static getLanguage() {
    return cache.local.get(LANGUAGE);
  }

  static setLanguage(language) {
    cache.local.set(LANGUAGE, language);
  }
}
